package com.cskaoyan.service;

import com.cskaoyan.bean.MarketStorage;
import com.cskaoyan.mapper.MarketStorageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

/**
 * 创建日期: 2022/05/08 22:55
 *
 * @author shuyang
 */
@Service
public class WXStorageServiceImpl implements WXStorageService {
    @Autowired
    MarketStorageMapper marketStorageMapper;

    @Override
    public MarketStorage storageUploadInVX(MultipartFile file) {
        //加入一个盐值
        String salt = "312dashuaibichang;i";
        boolean defaultDeletedStatus = false;
        int size = (int) file.getSize();
        String originalFilename = file.getOriginalFilename();
        String base = originalFilename+"/"+salt;
        String contentType = file.getContentType();
        String key = DigestUtils.md5DigestAsHex(base.getBytes())+".jpg";
        String url = "http://localhost:8083/image/" + key;
        MarketStorage marketStorage = new MarketStorage(key, originalFilename, contentType, size, url, new Date(), new Date());
        marketStorage.setDeleted(defaultDeletedStatus);
        marketStorageMapper.insertSelective(marketStorage);
        return marketStorage;
    }
}
